package com.construction.api.config.holder;

import com.construction.api.domain.model.token.Payload;
import com.construction.api.domain.model.token.User;
import com.construction.api.enums.RoleEnum;

/**
 * @author dybin
 * @Date: 2021/7/3 15:48
 */
public class PayloadHolder {

    private final static ThreadLocal<Payload> payloadHolder = new ThreadLocal<>();

    public static void add(Payload payload) {
        payloadHolder.set(payload);
    }

    public static void remove() {
        payloadHolder.remove();
    }

    public static Payload get() {
        return payloadHolder.get();
    }

    public static Integer projectId() {
        return payloadHolder.get().getProjectId();
    }

    public static RoleEnum roleId() {
        return payloadHolder.get().getRole();
    }

    public static User User() {
        return payloadHolder.get().getUser();
    }

}
